import { defineStore } from 'pinia';

type CarCheckoutState = {
  serviceType: string;
  airportInfo: any;
  hotelInfo: any;
  bookDate: string;
  bookTime: string;
  adultNumber: number;
  childrenNumber: number;
};

export const useCarCheckoutStore = defineStore('carcheckout', {
  state: () => {
    return {
      serviceType: 'PICKUP',
      airportInfo: {
        id: 0,
        showname: '',
        address: '',
      },
      hotelInfo: {
        id: 0,
        showname: '',
        address: '',
      },
      bookDate: '',
      bookTime: '',
      adultNumber: 1,
      childrenNumber: 0,
    } as CarCheckoutState;
  },
  getters: {

    /**
     * 时间
     */
    bookDateTime: (state) => {
      return state.bookDate + ' ' + state.bookTime;
    }
  },
  actions: {
    setServiceType(type: string) {
      this.serviceType = type;
    },
    setDateTime(date: string, time: string) {
      this.bookDate = date;
      this.bookTime = time;
    },
    setBookersNumber(adultsNumber: number, childrenNumber: number) {
      this.adultNumber = adultsNumber;
      this.childrenNumber = childrenNumber;
    },
    setAirportInfo(id: number, name: string, address: string) {
      this.airportInfo.id = id;
      this.airportInfo.showname = name;
      this.airportInfo.address = address;
    },
    setHotelInfo(id: number, name: string, address: string) {
      this.hotelInfo.id = id;
      this.hotelInfo.showname = name;
      this.hotelInfo.address = address;
    },
  }
});
